from typing import TypeVar, Generic

from mg_app_framework import MesCode


T = TypeVar('T')


class Response(Generic[T]):

    def __init__(self, code: str, data: T, msg: str):
        self.code = code
        self.data = data
        self.msg = msg

    @classmethod
    def success(cls, data=None, msg='OK') -> 'Response':
        return cls(MesCode.success, data, msg)

    @classmethod
    def fail(cls, msg='fail', data=None) -> 'Response':
        return cls(MesCode.fail, data, msg)
